package com.isky.visual.db.factory;

import com.isky.visual.constant.DbConstant;
import com.isky.visual.db.domain.DatabaseConfig;
import com.isky.visual.db.entity.Source;
import com.isky.visual.exception.GlobalException;
import com.isky.visual.result.CodeMsg;
import lombok.Builder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @version v1.0
 * @ProjectName visual_parent
 * @ClassName DBFactory
 * @Description 数据库工厂
 * @Author wudl
 * @Date DATE{TIME}
 */
@Builder
public class DbFactory {
    private static Logger log = LoggerFactory.getLogger(DbFactory.class);
    Source source;

    public DbFactory() {
    }

    public DbFactory( Source source) {
        this.source = source;
    }

    public IDbManager getDbManager() {
        if (source.getDbType().equals(DbConstant.MYSQL)) {
            return  new MySqlManager(source);
        } else if (source.getDbType().equals(DbConstant.Hive)) {
            return new PrestoManager(source);
        } else if (source.getDbType().equals(DbConstant.ORACLE)) {
            return new OracleManager(source);
        } else if (source.getDbType().equals(DbConstant.SQL_SERVER)) {
          return new SqlServerManager(source);
        }else if (source.getDbType().equals(DbConstant.PRESTO)){
            return new PrestoManager(source);
        }
        throw new GlobalException(CodeMsg.DB_CONN_TYPE_UNKNOW);
    }

}
